home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / INTERVIE / BUTTON.H < prev    next >
C/C++ Source or Header  |  1980-01-03  |  5KB  |  162 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * A button is a view of some value that is normally set when
  25.  * the button is pressed.
  26.  */
  27.  
  28. #ifndef button_h
  29. #define button_h
  30.  
  31. #include <InterViews/interactor.h>
  32. #include <InterViews/subject.h>
  33.  
  34. class Button;
  35. class ButtonList;
  36. class Bitmap;
  37.  
  38. class ButtonState : public Subject {
  39. public:
  40.     ButtonState();
  41.     ButtonState(int);
  42.     ButtonState(void*);
  43.  
  44.     void operator=(ButtonState&);
  45.     void SetValue(int);
  46.     void SetValue(void*);
  47.     void GetValue (int& v) { v = (int)value; }
  48.     void GetValue (void*& v) { v = value; }
  49. protected:
  50.     void* value;
  51.  
  52.     void Modify(void*);
  53. };
  54.  
  55. class Button : public Interactor {
  56. public:
  57.     void Attach(Button*);
  58.     void Detach(Button*);
  59.  
  60.     void Enable();
  61.     void Disable();
  62.  
  63.     void Choose();
  64.     void UnChoose();
  65.  
  66.     virtual void Press();
  67.     virtual void Refresh();
  68.  
  69.     void SetDimensions(int width, int height);
  70.  
  71.     virtual void Handle(Event&);
  72.     virtual void Update();
  73. protected:
  74.     Button(ButtonState*, void*);
  75.     Button(const char*, ButtonState*, void*);
  76.     Button(Painter*, ButtonState*, void*);
  77.     ~Button();
  78.  
  79.     void* value;        /* value associated with this button */
  80.     ButtonState* subject;    /* set to this->value when pressed */
  81.     ButtonList* associates;    /* enable/disable when chosen/unchosen */
  82.     boolean enabled;        /* can be pressed */
  83.     boolean chosen;        /* currently toggled on */
  84.     boolean hit;        /* currently being pushed */
  85. private:
  86.     void Init(ButtonState*, void*);
  87. };
  88.  
  89. class TextButton : public Button {
  90. protected:
  91.     const char* text;
  92.     Painter* background;
  93.     Painter* grayout;        /* for disabled buttons */
  94.  
  95.     TextButton(const char*, const char*, ButtonState*, void*);
  96.     TextButton(const char*, ButtonState*, void*);
  97.     TextButton(const char*, ButtonState*, void*, Painter*);
  98.     ~TextButton();
  99.  
  100.     void MakeBackground();
  101.     void MakeShape();
  102. private:
  103.     void Init(const char*);
  104. };
  105.  
  106. class PushButton : public TextButton {
  107. public:
  108.     PushButton(const char*, ButtonState*, int);
  109.     PushButton(const char*, ButtonState*, void*);
  110.     PushButton(const char*, const char*, ButtonState*, int);
  111.     PushButton(const char*, const char*, ButtonState*, void*);
  112.     PushButton(const char*, ButtonState*, int, Painter*);
  113.     PushButton(const char*, ButtonState*, void*, Painter*);
  114.  
  115.     virtual void Refresh();
  116. protected:
  117.     virtual void Reconfig();
  118.     virtual void Redraw(Coord, Coord, Coord, Coord);
  119. private:
  120.     void Init();
  121. };
  122.  
  123. class RadioButton : public TextButton {
  124. public:
  125.     RadioButton(const char*, ButtonState*, int);
  126.     RadioButton(const char*, ButtonState*, void*);
  127.     RadioButton(const char*, const char*, ButtonState*, int);
  128.     RadioButton(const char*, const char*, ButtonState*, void*);
  129.     RadioButton(const char*, ButtonState*, int, Painter*);
  130.     RadioButton(const char*, ButtonState*, void*, Painter*);
  131.  
  132.     virtual void Refresh();
  133. protected:
  134.     virtual void Reconfig();
  135.     virtual void Redraw(Coord, Coord, Coord, Coord);
  136. private:
  137.     void Init();
  138. };
  139.  
  140. class CheckBox : public TextButton {
  141. public:
  142.     CheckBox(const char*, ButtonState*, int, int);
  143.     CheckBox(const char*, ButtonState*, void*, void*);
  144.     CheckBox(const char*, const char*, ButtonState*, int, int);
  145.     CheckBox(const char*, const char*, ButtonState*, void*, void*);
  146.     CheckBox(const char*, ButtonState*, int, int, Painter*);
  147.     CheckBox(const char*, ButtonState*, void*, void*, Painter*);
  148.  
  149.     virtual void Press();
  150.     virtual void Refresh();
  151.     virtual void Update();
  152. protected:
  153.     virtual void Reconfig();
  154.     virtual void Redraw(Coord, Coord, Coord, Coord);
  155. private:
  156.     void* offvalue;
  157.  
  158.     void Init(void*);
  159. };
  160.  
  161. #endif
  162.